import java.util.Arrays;

public class Test {
    public static void func5(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j] > array[j+1]) {
                    swap(array,j,j+1);
                }
            }
        }
    }
    public static void main7(String[] args) {
        int[] array = {1,6,5,8,9,4,7,3,2};
        func5(array);
        System.out.println(Arrays.toString(array));
    }
    public static boolean func4(int[] array) {
        for (int i = 0; i < array.length-2; i++) {
            if(array[i]%2 != 0 && array[i+1]%2 != 0 && array[i+2]%2 != 0) {
                return true;
            }
        }
        return false;
    }
    public static void main6(String[] args) {
        int[] array = {2,6,4,1};
        boolean ret = func4(array);
        System.out.println(ret);
    }
    public static int func3(int[] array) {
        Arrays.sort(array);
        return array[array.length/2];
    }
    public static void main5(String[] args) {
        int[] array = {2,2,1,1,1,2,2};
        //int len = array.length / 2;
        int ret = func3(array);
        System.out.println(ret);
    }
    public static int func2(int[] array) {
        int ret = array[0];
        for (int i = 1; i < array.length; i++) {
            ret ^= array[i];
        }
        return ret;
    }
    public static void main4(String[] args) {
        int[] array = {4,1,2,1,2};
        int ret = func2(array);
        System.out.println(ret);
    }
    public static String func1(int[] array,int target) {
        String ret = "找不到";
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if(array[i] + array[j] == target) {
                    ret = "["+ i +","+ j +"]";
                }
            }
        }
        return ret;
    }
    public static void main3(String[] args) {
        int[] num = {2,7,11,15};
        String ret = func1(num,9);
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5,6};
        changeSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void swap(int[] array,int left,int right) {
        int tmp = array[right];
        array[right] = array[left];
        array[left] = tmp;
    }
    public static void changeSort(int[] array) {
        int left = 0;
        int right = array.length-1;
           while(left < right) {
               while(left <right && array[left]%2 != 0) {
                   left++;
               }
               while(left < right && array[right]%2 == 0) {
                   right--;
               }
                   swap(array,right,left);
           }

    }
    public static void main1(String[] args) {
        int[] array = {1,2,3};
        transform(array);
        System.out.println(Arrays.toString(array));
    }
    public static void transform(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] *= 2;
        }
    }
}
